<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ymPrompt/ymPrompt_Ex.js"></script>
<!--所在城市-->
<script type="text/javascript" src="__PUBLIC__/js/form_check/jquery.validator.reg.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/form_check/jquery.corners.min.js"></script>
<link href="__THEME__/layout.css" rel="stylesheet" type="text/css" />
<link href="../Public/pop.css" rel="stylesheet" type="text/css" />

<body>
    <script type="text/javascript">
        <!--
        //指定当前组模块URL地址
        var URL = '__URL__';
        var APP = '__APP__';
        var PUBLIC = '__PUBLIC__';
        var ROOT = '__ROOT__';
    //-->
    </script>

    <script>
        function addMedicine(categoryid) {
            var name = $.trim($("#name").val());
            if (!name) {
                ymPrompt.close();
                ymPrompt.alert("药品名称不能为空!");
                return;
            }
            // var gid  = $("#gid option:selected").val();
            $.post(APP + "/Index/addMedicine", {name: name, categoryid: categoryid}, function(json) {
                var json = eval('(' + json + ')');
                if (json.status == 1) {
                    ymPrompt.close();
                    ymPrompt.alert(json.info);
                } else {
                    ymPrompt.close();
                    ymPrompt.alert(json.info);
                }
            });

        }
    </script>

    <div class="pop">
        <div class="con">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" style="height:120px;">
                <tr>
                    <td>城市：<input type="hidden" name="ts_areaval" id="ts_areaval" value="{$info.ts_areaval}"/>
                        <input type="text" class="TextH20" style="width:100px;" onfocus="this.className = 'Text2'" onblur="this.className = 'TextH20'" value="{$info.area}" name="areaval" disabled  id="areaval" /> 
                        <input type="button" class="btn_b" value="选择地区" selectArea="true" level="2" areatype="areaval" ></td>
                    <td>医院：<input type="text" id="name" name="name" value="" placeholder="请输入药品名称"></td>
                </tr>
                <!-- <tr id="f_group">
                     <td>分组：</td>
                     <td id="tishi"><select name="gid" id="gid">
                             <volist name="user_groups" id="g">
                                 <option value="{$g.id}">{$g.name}</option>
                             </volist>
                     </select></td>
                 </tr>-->
            </table>
        </div>
        <div class="btm" id="f_button">
            <input name="input" type="button" class="btn_b" value="确 定"  onclick="addMedicine({$_GET['categoryid']})"/>
            <input name="input2" type="button" class="btn_w" value="取 消" onclick="ymPrompt.close();" />
        </div>
    </div>
<script type="text/javascript">
	var arrArea = new Array();
	var arrAreaTitle = new Array();
	var arealevel = 2;  //调用城市的级别
	var type;

	$("[selectArea='true']").bind("click", function(){
	    type = $(this).attr('areatype');
	    if($(this).attr('level')){
	    	arealevel = $(this).attr('level');
	    }
		var selected = $("#ts_"+type).val();
		var selectarr = selected.split(',');
		var selecttext = $("#"+type).val().split(' ');
		
	    var html = '<div class="pop" id="pop_network">'+
	    		   '<div id="pop_ullist" class="pop_ullist"></div>'+
	    		   '<div style="margin:3px;color:red;clear:both;text-align:left;" id="selectmessage">'+
	               '&nbsp;</div></div><div class="btm" id="f_button">'+
                   '<input name="input" type="button" class="btn_b" value="确 定"  onclick="save()"/>'+
                   '<input name="input2" type="button" class="btn_w" value="取 消" onclick="ymPrompt.close();" /></div>'+
                   '</div>';
	    ymPrompt.win(html,625,arealevel*85+100,'选择地区');
	    
	    //添加级数
	    for(var i=1;i<=arealevel;i++){   	
	    	addUL(i);
	    	addSelect(i);
	    }	    
	    
	    if(selectarr.length>1){
	    	for(var i=1;i<=selectarr.length;i++){
	    		$("#select_"+i).html(selecttext[(i-1)]);
	    		arrArea[i] = selectarr[(i-1)];
	    	}
	    	getLiList(selected,'init',arealevel);
	    }else{
		    getLiList(0,0,0);
	    }
	});
	
	//选择下级地区
	function selectarea(id,level,title){
		if(arrArea[level]){
			$("#node_"+arrArea[level]).attr('class','noon');
		}
		arrArea[level]       = id;
		arrAreaTitle[level]  = title;
		
		for(var i=1;i<=arealevel;i++){
			if(i>level){
				$("#list_"+i).html('');
				$("#select_"+i).html('');
			}
		}		
		
		
		$("#node_"+id).attr('class','on');
		$("#select_"+level).html(title);
		if(level < arealevel){
			getLiList(arrArea.join(','),level,0);
		}

	}
	
	function getLiList(pid,level,arealevel){
		if(pid!=0 && level!='init'){
			var p = parseInt(level)+1;
			 $("#list_"+p).html('<li><img src="http://192.168.1.111/public/images/logging.gif></li>');
		}
	    $.post('http://192.168.1.111/index.php?s=/Index/getNetwork/', {pid:pid,level:level,arealevel:arealevel}, function(txt){
	    	if(txt){
	    		if(level=='init'){
	    			$("#pop_ullist").html(txt);
	    		}else{
	    			level++;
		    		 $("#list_"+level).html(txt);
	    		}
	    	}
	    });		
	}
	
	function addUL(level){
		if(!$("#list_"+level).is('ul')){
			$('#pop_ullist').append('<div class="con"><ul class="ullist" id="list_'+level+'">&nbsp;</ul></div>');
		}
	}
	
	function addSelect(i){
		if(!$("#select_"+i).is('span')){
			$("#selectmessage").append('<span id="select_'+i+'" style="margin-left:5px;">&nbsp;</span>');
		}
	}
	
	function save(){
		if(arrArea.length==0){
			alert('请选择地区');
		}else{
			$("#"+type).val($.trim(arrAreaTitle.join(' ')));
			arrArea.splice(0,1);
			$("#ts_"+type).val(arrArea);
			ymPrompt.close();
		}
	}
	

</script>
</body>
